$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'college/Select',
        datatype: "json",
        colModel: [
            { label: '学院/部门名称', name: 'collegeName', width: 100 ,key: true },
            { label: '学院/部门代码', name: 'collegeCode', width: 100 }
        ],
        viewrecords: true,
        height:'100%',
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        // rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    new AjaxUpload('#upload', {
                action: baseURL + 'PersonnelData/ExcelImport/CollegeInfo?token=' + token,
                name: 'file',
                autoSubmit:true,
                responseType:"json",
                onSubmit:function(file, extension){
                    if (!(extension && /^(xls|xlsx)$/.test(extension.toLowerCase()))){
                        alert('只支持excel上传！');
                        return false;
                    }
                },
                onComplete : function(file, r){
                    if(r.code == 0){
                        alert("上传成功");
                    }else{
                        alert(r.msg);
                    }
                }
            });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            key: null
        },
        showList: true,
        title: null,
        uploadCount:null,
        dialogProgressVisible:false,
        webSocket:null,
        term: {}
    },
    created(){
                this.initWebSocket()
            },
    methods: {
        initWebSocket:function(){
            this.webSocket=new WebSocket("ws://"+localStorage.getItem("webSocketPort")+"/webSocket?token="+token);
            this.webSocket.onmessage=this.websocketonmessage;
            this.webSocket.onclose = this.websocketclose;
            console.log("建立连接")
        },
        websocketonmessage:function(e){ //数据接收
            console.log(e.data);
            vm.uploadCount=e.data;
            vm.dialogProgressVisible=true;
            if(e.data=="100.0"){
             vm.dialogProgressVisible=false;
            }
        },
        websocketsend(agentData){//数据发送
            this.websock.send(agentData);
        },
        websocketclose(e){  //关闭
            console.log("connection closed (" + e.code + ")");
        },
        query: function () {
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{ 'collegeName': vm.q.key},
                page:page
            }).trigger("reloadGrid");
        },
        validator: function () {
            if(isBlank(vm.term.schoolAcademicYear)){
                alert("学年不能为空");
                return true;
            }

            if(isBlank(vm.term.schoolAcademicTerm)){
                alert("学期不能为空");
                return true;
            }
            if(isBlank(vm.term.startDate)){
                alert("开始时间不能为空");
                return true;
            }
            if(isBlank(vm.term.endDate)){
                alert("结束时间不能为空");
                return true;
            }
            if(isBlank(vm.term.currentTerm)){
                alert("当前学期不能为空");
                return true;
            }
            if(isBlank(vm.term.teachingWeekNum)){
                alert("教学周长度不能为空");
                return true;
            }
        }
    }
});